package com.thread;

public class TestThread2 {
	private static final Integer obj = new Integer(0);
	
	private static String s  = "str...........str.............";

	public  void m4t1() {
		synchronized (this) {
			int i = 5;
			while (i-- > 0) {
				System.out
						.println(Thread.currentThread().getName() + ".. : " + i);
//				try {
//					Thread.sleep(500);
//				} catch (InterruptedException ie) {
//				}
			}
			s = "44444444";
		}
	
		
	}

	public static void m4t2() {
	synchronized(obj){
			int i = 5;
			while (i-- > 0) {
				System.out.println(Thread.currentThread().getName() + " : " + i);
//				try {
//					Thread.sleep(500);
//				} catch (InterruptedException ie) {
//				}
			}
			
			s = "5555555555";
	}
	}

	public static void main(String[] args) {
		final TestThread2 myt2 = new TestThread2();
		Thread t1 = new Thread(new Runnable() {
			public void run() {
				
				myt2.m4t1();
				TestThread2.m4t2();
			}
		}, "t1");
		Thread t2 = new Thread(new Runnable() {
			public void run() {
				
				
				TestThread2.m4t2();
				myt2.m4t1();
				
			}
		}, "t2");
		
//		Thread t3 = new Thread(new Runnable() {
//			public void run() {
//				TestThread2.m4t1();
//				TestThread2.m4t2();
//			}
//		}, "t3");
		t1.start();
		t2.start();
//		t3.start();
		try {
			Thread.currentThread().sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(s);
	}
}
